package com.crm.holidayConfig.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crm.holidayConfig.mapper.HolidayConfigMapper;
import com.crm.holidayConfig.domain.HolidayConfig;
import com.crm.holidayConfig.service.IHolidayConfigService;

/**
 * 节假日历Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-29
 */
@Service
public class HolidayConfigServiceImpl implements IHolidayConfigService {
    @Autowired
    private HolidayConfigMapper holidayConfigMapper;

    /**
     * 查询节假日历
     *
     * @param holiday 节假日历主键
     * @return 节假日历
     */
    @Override
    public HolidayConfig selectHolidayConfigByHoliday(String holiday) {
        return holidayConfigMapper.selectHolidayConfigByHoliday(holiday);
    }

    /**
     * 查询节假日历列表
     *
     * @param holidayConfig 节假日历
     * @return 节假日历
     */
    @Override
    public List<HolidayConfig> selectHolidayConfigList(HolidayConfig holidayConfig) {
        return holidayConfigMapper.selectHolidayConfigList(holidayConfig);
    }

    /**
     * 新增节假日历
     *
     * @param holidayConfig 节假日历
     * @return 结果
     */
    @Override
    public int insertHolidayConfig(HolidayConfig holidayConfig) {
        return holidayConfigMapper.insertHolidayConfig(holidayConfig);
    }

    /**
     * 修改节假日历
     *
     * @param holidayConfig 节假日历
     * @return 结果
     */
    @Override
    public int updateHolidayConfig(HolidayConfig holidayConfig) {
        return holidayConfigMapper.updateHolidayConfig(holidayConfig);
    }

    /**
     * 批量删除节假日历
     *
     * @param holidays 需要删除的节假日历主键
     * @return 结果
     */
    @Override
    public int deleteHolidayConfigByHolidays(String[] holidays) {
        return holidayConfigMapper.deleteHolidayConfigByHolidays(holidays);
    }

    /**
     * 删除节假日历信息
     *
     * @param holiday 节假日历主键
     * @return 结果
     */
    @Override
    public int deleteHolidayConfigByHoliday(String holiday) {
        return holidayConfigMapper.deleteHolidayConfigByHoliday(holiday);
    }

    /**
     * 判断日期是否节假日
     *
     * @param date 日期
     * @return
     */
    @Override
    public boolean isHoliday(Date date) {
        HolidayConfig holidayConfig = holidayConfigMapper.selectHolidayConfigByHoliday(DateUtils.parseDateToStr(DateUtils.YYYYMM, date));
        if (holidayConfig == null) {
            return false;
        }
        return holidayConfig.getHoliday() != null;
    }

}
